@extends('backstage.layout.master')
@section('title', '添加用户')
@section('style')
    <style>
        a{
            cursor: pointer;
        }
        .search-tool{
            margin-bottom: 20px;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/module/module-list">模块管理</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                添加用户
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12 search-tool">
                <div class="well">
                    <select name="user_type" id="user_type" disabled>
                        {{--<option value="0">全部</option>--}}
                        <option @if($app_id == 2 || ((isset($conditions->user_type) && $conditions->user_type == 1))) selected @endif value="1">设计师</option>
                        <option @if($app_id == 5 || ((isset($conditions->user_type) && $conditions->user_type == 2))) selected @endif value="2">品牌商</option>
                    </select>
                    <input type="text" class="keyword1" name="user_param" placeholder="用户昵称/手机号" value="{{isset($conditions->user_param) ? $conditions->user_param : ''}}">
                    <input type="button" value=" 搜索 " class="button_search">
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <form class="form-horizontal" role="form" action="backstage/module/add-data" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                    <input type="hidden" name="find_module_id" value="{{$find_module_id}}">
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th class="center">用户ID</th>
                            <th class="center">用户昵称</th>
                            <th class="center">手机号码</th>
                            <th class="center">用户状态</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach($users as $user)
                        <tr>
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace" name="data_ids[]" value="{{$user->user_id}}">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td class="center">{{ $user->user_id }}</td>
                            <td class="center">{{ $user->nick_name }}</td>
                            <td class="center">{{ $user->phone }}</td>
                            <td class="center">
                                {{ $user->user_type_name }}
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <div class="row">
                        <div>
                            <div class="dataTables_paginate paging_bootstrap">
                                @if(empty($conditions))
                                    <?php echo $users->render(); ?>
                                    @else
                                    <?php echo $users->appends(['conditions' => json_encode($conditions)])->render(); ?>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-5 col-md-7">
                        <button class="btn btn-info" type="submit">
                            <i class="icon-ok bigger-110"></i>
                            添加
                        </button>
                    </div>
                </div>
                </form>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $(".button_search").click(function(){
                var user_type = $("#user_type option:selected").val();
                var user_param = $(".keyword1").val();
                search(user_type,user_param);
            });
        });
        function search(user_type,user_param){
            var json = '{ "user_type" : "'+ user_type +'", "user_param" : "'+ user_param +'"}';
            console.log(json);
            window.location.href = "backstage/module/add-data/"+'{{$find_module_id}}'+"?conditions="+json;
        }

    </script>
@stop